/*
route_library.js

Primary Author: Tyler Mazaika
Coin 71 Team 1
Palo Alto Bicycle Club 

-----------------------------

click on link -> load the routetext partial via contentLoader


*/

var ROUTE_INDEX;	// stores selected route

// loads a new page containing information about a route in routelibrary.xml
function getRoutePage(index) {
	
	ROUTE_INDEX = index;
	var contentLoader = new net.ContentLoader("routelibrary.xml", createRouteTextPage);
	var contentArea = document.getElementById('contentArea');
	contentArea.innerHTML = "<div id='routeText'></div>";
}

// constructs a page for viewing the text of a route based on data stored in an xml <route>
function createRouteTextPage() {

	var xmlDoc = this.req.responseXML;
	var route = xmlDoc.getElementsByTagName("route")[ ROUTE_INDEX ];	
	
	var container = document.getElementById('routeText');	
	var newHtml = "";
	
	newHtml += "<a id='rl_link1' href='javascript:void(0);'>&lt;&lt; Back to Route Library</a>" +
		"<h3>" + route.getElementsByTagName("title")[0].firstChild.data + 
		" : " + route.getElementsByTagName("category")[0].firstChild.data +
		" / " + route.getElementsByTagName("hilliness")[0].firstChild.data + 
		" / " + route.getElementsByTagName("mileage")[0].firstChild.data + 
		"</h3><pre>" + route.getElementsByTagName("text")[0].firstChild.data + "</pre>" +
		"<a id='rl_link2' href='javascript:void(0);'>&lt;&lt; Back to Route Library</a>";
	
	container.innerHTML = newHtml;
	
	document.getElementById("rl_link1").onclick=goToRouteLibrary;
	document.getElementById("rl_link2").onclick=goToRouteLibrary;
}
